package com.hq.fxh.No3_TuiGuang.Activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hq.fxh.HttpApi.UserServiceImpl;
import com.hq.fxh.Intefers.NetworkSubscriber;
import com.hq.fxh.Modle.GetPushDetailInfoRes;
import com.hq.fxh.No0_ChengQu.Activity.BaseActivity;
import com.hq.fxh.No3_TuiGuang.Adaoter.PushDetailInfoActivityAdapter;
import com.hq.fxh.No3_TuiGuang.MyMoBan.Activity.item.ToastUtils;
import com.hq.fxh.R;


import cn.jiguang.analytics.android.api.JAnalyticsInterface;



public class PushDetailInfoActivity extends BaseActivity {

    private ImageView back;
    private TextView tv_name;
    private TextView tv_scale;
    private RecyclerView business_recycler;
    LinearLayoutManager layoutManager;
    private PushDetailInfoActivityAdapter pushDetailInfoActivityAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_push_detail_info;
    }

    @Override
    protected void initView() {
        setSysColor(R.color.red,true);
        back = (ImageView) findViewById(R.id.back);
        tv_name = (TextView) findViewById(R.id.tv_name);
        tv_scale = (TextView) findViewById(R.id.tv_scale);
        business_recycler = (RecyclerView) findViewById(R.id.business_recycler);
    }

    @Override
    protected void initData() {
        layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        business_recycler.setLayoutManager(layoutManager);
        business_recycler.setHasFixedSize(true);
        getPushDetailInfo();
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        JAnalyticsInterface.onPageStart(this,"互推信息");
    }

    @Override
    protected void onPause() {
        super.onPause();
        JAnalyticsInterface.onPageEnd(this,"互推信息");
    }

    private void getPushDetailInfo() {
        UserServiceImpl.getPushDetailInfo(new NetworkSubscriber<GetPushDetailInfoRes>() {
            @Override
            public int onSuccess(GetPushDetailInfoRes data) {
                super.onSuccess(data);
                if (data != null && data.getCode() == 0) {
                    GetPushDetailInfoRes.DataBean pushDetailInfo = data.getData();
                    tv_name.setText(pushDetailInfo.getCompany_name());
                    tv_scale.setText("规模： " + pushDetailInfo.getEmployee_num());
                    if (pushDetailInfoActivityAdapter == null) {
                        pushDetailInfoActivityAdapter = new PushDetailInfoActivityAdapter(PushDetailInfoActivity.this, pushDetailInfo);
                        business_recycler.setAdapter(pushDetailInfoActivityAdapter);
                        pushDetailInfoActivityAdapter.notifyDataSetChanged();
                    }
                } else {
                    ToastUtils.show(PushDetailInfoActivity.this, data.getMsg());
                }
                return 0;
            }
        });
    }
}
